package com.zxl.always.on.display.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.zxl.always.on.display.R;

/**
 * Created by Administrator on 2018/3/2.
 */

public class TabGroupView extends LinearLayout implements View.OnClickListener {

    private TabItemView item1, item2, item3;

    private OnItemClickListener mOnItemClickListener;

    public TabGroupView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        item1 = findViewById(R.id.item1);
        item1.setOnClickListener(this);
        item2 = findViewById(R.id.item2);
        item2.setOnClickListener(this);
        item3 = findViewById(R.id.item3);
        item3.setOnClickListener(this);

        item1.setInfo(R.string.settings_custom_clock_style, R.drawable.aod_setting_clock_icon_style);
        item2.setInfo(R.string.settings_custom_color, R.drawable.aod_setting_clock_icon_color);
        item3.setInfo(R.string.settings_custom_background, R.drawable.aod_setting_clock_icon_background);
    }

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.item1:
                setCheckedPosition(0);
                if (null != mOnItemClickListener) {
                    mOnItemClickListener.onItemClick(0);
                }
                break;
            case R.id.item2:
                setCheckedPosition(1);
                if (null != mOnItemClickListener) {
                    mOnItemClickListener.onItemClick(1);
                }
                break;
            case R.id.item3:
                setCheckedPosition(2);
                if (null != mOnItemClickListener) {
                    mOnItemClickListener.onItemClick(2);
                }
                break;
            default:
                setCheckedPosition(-1);
                break;
        }
    }

    public void setCheckedPosition(int position) {
        switch (position) {
            case 0:
                item1.setChecked(true);
                item2.setChecked(false);
                item3.setChecked(false);
                break;
            case 1:
                item1.setChecked(false);
                item2.setChecked(true);
                item3.setChecked(false);
                break;
            case 2:
                item1.setChecked(false);
                item2.setChecked(false);
                item3.setChecked(true);
                break;
            default:
                item1.setChecked(false);
                item2.setChecked(false);
                item3.setChecked(false);
                break;
        }
    }

    public interface OnItemClickListener {

        void onItemClick(int position);

    }
}
